package com.bite.demo.controller;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {
    //登录接口
    @RequestMapping("login")
    public String login(String userName, String password, HttpSession session) {
        //1.参数校验
        //2.验证用户名和密码
        //3.存Session
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return "用户名或密码为空";
        }
        //没学数据库，先写死数据
        if(!"zhangsan".equals(userName) && !"123456".equals(password)) {
            return "账号或密码错误";
        }
        //存储Session
        session.setAttribute("userName",userName);
        return "登录成功!";
    }
}
